<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
   <!-- <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div> -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="oneSlot" slot-scope="text,record">
          <div>
            直推男用户金币充值: {{record.oneLevelManGold}}%
          </div>
          <div>
            直推女用户社交收益: {{record.oneLevelWomanIncome}}%
          </div>
        </template>
        <template slot="twoSlot" slot-scope="text,record">
          <div v-if="record.itemDetail" v-for="item in JSON.parse(record.itemDetail)">
            旗下用户为等级{{item.eventGrade}}，拿{{item.eventName}}的：{{item.rate}}%
          </div>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="openLevelTasks(record)">等级任务</a>
          <a-divider type="vertical" />
          <a @click="handleEdit(record)">修改</a>
        </span>

      </a-table>
    </div>

    <reward-rules-modal ref="modalForm" @ok="modalFormOk"></reward-rules-modal>
    <Level-Tasks-List ref="LevelTasksList" @ok="modalFormOk"></Level-Tasks-List>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import RewardRulesModal from './modules/RewardRulesModal'
  import LevelTasksList from './LevelTasksList'

  export default {
    name: 'RewardRulesList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      RewardRulesModal,
      LevelTasksList
    },
    data () {
      return {
        description: '奖励规则管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'等级名称',
            align:"center",
            width:200,
            dataIndex: 'gradeName'
          },
          {
            title:'等级',
            align:"center",
            width:100,
            dataIndex: 'grade'
          },
          {
            title:'一级佣金',
            align:"center",
            dataIndex: 'oneLevelManGold',
            scopedSlots: {customRender: 'oneSlot'},
          },
          {
            title:'二级佣金',
            align:"center",
            dataIndex: 'oneLevelWomanIncome',
            scopedSlots: {customRender: 'twoSlot'},
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        isorter:{
        column: 'grade',
        order: 'asc',
      },
        url: {
          list: "/system/rewardRules/list",
          delete: "/system/rewardRules/delete",
          deleteBatch: "/system/rewardRules/deleteBatch",
          exportXlsUrl: "/system/rewardRules/exportXls",
          importExcelUrl: "system/rewardRules/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'gradeName',text:'等级名称',dictCode:''})
        fieldList.push({type:'string',value:'grade',text:'等级',dictCode:''})
        fieldList.push({type:'string',value:'oneLevelManGold',text:'一级佣金-直推男用户金币充值',dictCode:''})
        fieldList.push({type:'string',value:'oneLevelWomanIncome',text:'一级佣金-直推女用户社交收益',dictCode:''})
        this.superFieldList = fieldList
      },

      //打开等级任务
      openLevelTasks(record){
        this.$refs.LevelTasksList.initData(record.id);
        this.$refs.LevelTasksList.parentId = record.id;
        this.$refs.LevelTasksList.visible=true;
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>